﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// RippleEffect Effect
    /// </summary>
    public class RippleEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(RippleEffect), new UIPropertyMetadata(new Point(0.5, 0.5), ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty AmplitudeProperty = DependencyProperty.Register("Amplitude", typeof(double), typeof(RippleEffect), new UIPropertyMetadata(0.1, ShaderEffect.PixelShaderConstantCallback(1)));
        public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof(double), typeof(RippleEffect), new UIPropertyMetadata(50.0, ShaderEffect.PixelShaderConstantCallback(2)));
        public static readonly DependencyProperty PhaseProperty = DependencyProperty.Register("Phase", typeof(double), typeof(RippleEffect), new UIPropertyMetadata(0.0, ShaderEffect.PixelShaderConstantCallback(3)));
        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(RippleEffect), 0);

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(RippleEffect.InputProperty));
            }
            set
            {
                this.SetValue(RippleEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Amplitude du Shader
        /// </summary>
        public double Amplitude
        {
            get
            {
                return ((double)this.GetValue(RippleEffect.AmplitudeProperty));
            }
            set
            {
                this.SetValue(RippleEffect.AmplitudeProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Center du Shader
        /// </summary>
        public Point Center
        {
            get
            {
                return ((Point)this.GetValue(RippleEffect.CenterProperty));
            }
            set
            {
                this.SetValue(RippleEffect.CenterProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Frequency du Shader
        /// </summary>
        public double Frequency
        {
            get
            {
                return ((double)this.GetValue(RippleEffect.FrequencyProperty));
            }
            set
            {
                this.SetValue(RippleEffect.FrequencyProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Phase du Shader
        /// </summary>
        public double Phase
        {
            get
            {
                return ((double)this.GetValue(RippleEffect.PhaseProperty));
            }
            set
            {
                this.SetValue(RippleEffect.PhaseProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur statique
        /// </summary>
        static RippleEffect()
        {
            RippleEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/Ripple.ps");
        }

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        public RippleEffect()
        {
            this.PixelShader = RippleEffect._PixelShader;

            this.UpdateShaderValue(RippleEffect.CenterProperty);
            this.UpdateShaderValue(RippleEffect.AmplitudeProperty);
            this.UpdateShaderValue(RippleEffect.PhaseProperty);
            this.UpdateShaderValue(RippleEffect.FrequencyProperty);
            this.UpdateShaderValue(RippleEffect.InputProperty);
        }

        #endregion
    }
}
